<?php

namespace app\admin\controller\member;

use app\admin\model\UM as UM;
use app\admin\service\MemberStatisticsService;
use ShidianUtil\Thinkphp\Response\ApiResponse;
use think\APP;
use think\Request as Request;

/**
 * MemberStatistics 控制器
 * Class MemberStatistics
 * @package app\member\controller
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037509
 */
class MemberStatistics
{
    private Request $request;

    private MemberStatisticsService $service;

    public function __construct(Request $request, MemberStatisticsService $memberStatisticsService)
    {
        $this->request = $request;
        $this->service = $memberStatisticsService;
    }

    /**
     * 用户统计
     * @param UM|null $user
     * @return ApiResponse
     * @url /member/member_statistics/read
     */
    public function read(?UM $user): ApiResponse
    {
        $request = $this->request;

        $channel = $request->param('channel');
        $chain = $request->param('chain');
        $provinceId = $request->param('provinceId');
        $cityId = $request->param('cityId');
        $startTime = $request->param('startTime');
        $endTime = $request->param('endTime');
        $kw = $request->param('kw');
        $inviteId = $request->param('inviteId');

        return ApiResponse::success($this->service->read($user, $channel, $chain, $provinceId, $cityId, $startTime, $endTime, $kw, $inviteId));
    }

}
